package com.example.api.service.impl;

import com.example.api.mapper.ApiMapper;
import com.example.api.model.TbConfig;
import com.example.api.service.ApiService;
import com.example.api.util.SpringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @program: api_limit
 * @description:
 * @author: Mr.chen
 * @create: 2020-02-18 20:57
 **/
@Service
public class ApiServiceImpl implements ApiService {

    @Autowired
    private ApiMapper apiMapper ;

    @Override
    public void insertConfig(List<TbConfig> tbConfigs) {
        for (TbConfig tbConfig : tbConfigs) {
            TbConfig config = apiMapper.getConfig(tbConfig.getConfigName());
            if(null == config){
                apiMapper.insertConfig(tbConfig);
            }
        }
    }

    @Override
    public Long getConfigValue(String configName) {
        TbConfig config = apiMapper.getConfig(configName);
        return Long.valueOf(config.getConfigValue());
    }
}
